package com.lcredu.dao.impl;

import com.lcredu.dao.BasicDAO;
import com.lcredu.dao.OrderItemDAO;
import com.lcredu.entity.OrderItem;

import java.util.Collections;
import java.util.List;

/**
 * @author 黎长容
 * @date 2025-07-09 11:16
 */
public class OrderItemDAOImpl extends BasicDAO<OrderItem> implements OrderItemDAO {
    @Override
    public int savaOrderItem(OrderItem orderItem) {
        String saveSql = "INSERT INTO `order_item`(`id`,`name`,`price`,`count`,`total_price`,`order_id`) VALUES (NULL,?,?,?,?,?)";
        return update(saveSql, orderItem.getName(), orderItem.getPrice(), orderItem.getCount(), orderItem.getTotalPrice(), orderItem.getOrderId());
    }

    @Override
    public List<OrderItem> getOrderItems(String orderId) {
        String sql = "select id, name, price, count, total_price, order_id as orderId from order_item where order_id = ?";
        List<OrderItem> orderItems = queryMulti(sql, OrderItem.class, orderId);
        return orderItems;
    }
}
